//Copyright (c) Microsoft Corporation. All rights reserved.
using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;

namespace Microsoft.Office.OneNote.UnitTests
{
	[TestFixture]
	public class HierarchyNodeTest
	{
		[Test]
		public void SynchronizationLocks()
		{
			HierarchyNode node = OneNote.Application.NotebookRoot;

			Assert.IsFalse(node.SynchronizationLocked);
			Assert.IsFalse(node.SynchronizationLockedForRead);
			Assert.IsFalse(node.SynchronizationLockedForWrite);

			using (HierarchySynchronizationLocker readLock = new HierarchySynchronizationLocker(node))
			{
				Assert.IsTrue(node.SynchronizationLocked);
				Assert.IsTrue(node.SynchronizationLockedForRead);
				Assert.IsFalse(node.SynchronizationLockedForWrite);
			}

			Assert.IsFalse(node.SynchronizationLocked);
			Assert.IsFalse(node.SynchronizationLockedForRead);
			Assert.IsFalse(node.SynchronizationLockedForWrite);

			using (HierarchySynchronizationLocker readLock = new HierarchySynchronizationLocker(node, HierarchySynchronizationLocker.Mode.ForWrite))
			{
				Assert.IsTrue(node.SynchronizationLocked);
				Assert.IsFalse(node.SynchronizationLockedForRead);
				Assert.IsTrue(node.SynchronizationLockedForWrite);
			}
		}
	}
}
